<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <style>
    #app {
        width: 400px;
        height: 400px;
        background: rgba(0, 0, 0, 0.3);
        margin: 100px auto 0;
    }
    #li{
        width: 300px;
        height: 150px;
        background:pink;
        margin-bottom:20px;
    }
    #yu{
        width: 300px;
        height: 150px;
        background:pink;
    }
</style>
</head>

<body>
  <div id="app">

    <Child></Child>
    <Child2></Child2>


  </div>

  <script id="child" type="text/x-template">
    <div id="li">
      <h3>李雨航的年龄{{name}}</h3>
      <button id="btn" @click="aaa">加</button>
    </div>
  </script>
  <script id="child2" type="text/x-template">
    <div id="yu">
     <span>王桂敏的年龄{{age}}</span>
     <button id="btn2" @click="bbb">减 </button>
    </div>
  </script>
  <script src="./js/vue.js"></script>
  <script>

    // 局部组件注册
    const Child = {
        data(){
            return {  name:18 }
        },
        template: '#child',
        methods:{
            aaa(){
                if(this.name==30){
                    btn.style.background="red";
                    return false;
                }else{
                    this.name ++
                }
            }
      },
       
    }
    const Child2 = {
        data(){
            return {  age:30 }
        },
        template: '#child2',
        methods:{
            bbb(){
                if(this.age==18){
                    btn2.style.background="red";
                    return false;
                }else{
                    this.age --
                }
            }
        }
    }

    // Vue实例 根组件
    const app = new Vue({
      el: '#app',
      data: {

      },
      
      // 注册局部组件
      components: {
        // 原本是：Child ：Child    因为Key和Value的值一样，所以省略
        Child,
        Child2
      }
    })
  </script>
</body>

</html>